﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

// Created libraries
using FrbaBus.Core;

namespace FrbaBus.Consulta_Puntos_Adquiridos
{
    public partial class Consulta2 : Form
    {
        public Consulta2()
        {
            InitializeComponent();
        }

        private void Consulta2_Load(object sender, EventArgs e)
        {
            dataGridView1.ReadOnly = true;
            dataGridView1.AllowUserToAddRows = false;
            dataGridView1.AllowUserToDeleteRows = false;
            dataGridView2.ReadOnly = true;
            dataGridView2.AllowUserToAddRows = false;
            dataGridView2.AllowUserToDeleteRows = false;
            ConsultaPuntos frm = new ConsultaPuntos();
            label3.Text = frm.GetNumber();
            DBManager db = new DBManager();
            SqlCommand consulta = new SqlCommand("select (SUM(Puntos)-SUM(Acreditados)) from ALL_IN.PuntajesHastalaFecha where DNI = '" + label3.Text + "'");
            SQLResponse r = db.executeQuery(consulta);
            label6.Text = r.result.Rows[0][0].ToString();
            SqlCommand consulta2 = new SqlCommand("select SUM(Puntos) from ALL_IN.PuntajesHastalaFecha where DNI = '" + label3.Text + "'");
            SqlCommand consulta3 = new SqlCommand("select SUM(Acreditados) from ALL_IN.PuntajesHastalaFecha where DNI = '" + label3.Text + "'");
            SQLResponse r2 = db.executeQuery(consulta2);
            SQLResponse r3 = db.executeQuery(consulta3);
            label8.Text = r2.result.Rows[0][0].ToString();
            label10.Text = r3.result.Rows[0][0].ToString();
            SqlCommand consulta4 = new SqlCommand("select Fecha_Salida, Desde, Hacia, Puntos from ALL_IN.PuntajesyRecorridos where DNI = '" + label3.Text + "'");
            SQLResponse r4 = db.executeQuery(consulta4);
            SqlCommand consulta5 = new SqlCommand("select count(*) from ALL_IN.PuntajesyRecorridos where DNI = '" + label3.Text + "'");
            SQLResponse r5 = db.executeQuery(consulta5);
            int valor = (int)r5.result.Rows[0][0];
            for (int i = 0; i < valor; i++)
            {
                dataGridView1.Rows.Add(r4.result.Rows[i][0].ToString(), r4.result.Rows[i][1].ToString(), r4.result.Rows[i][2].ToString(), r4.result.Rows[i][3].ToString());
            }
            SqlCommand consulta6 = new SqlCommand("select Fecha_Canje, Cantidad, Valor_Puntos, Nombre from ALL_IN.CanjeyProducto where DNI = '" + label3.Text + "'");
            SQLResponse r6 = db.executeQuery(consulta6);
            SqlCommand consulta7 = new SqlCommand("select count(*) from ALL_IN.CanjeyProducto where DNI = '" + label3.Text + "'");
            SQLResponse r7 = db.executeQuery(consulta7);
            int valor2 = (int)r7.result.Rows[0][0];
            for (int i = 0; i < valor2; i++)
            {
                dataGridView2.Rows.Add(r6.result.Rows[i][0].ToString(), r6.result.Rows[i][1].ToString(), r6.result.Rows[i][2].ToString(), r6.result.Rows[i][3].ToString());
            }

            db.desconectar();
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            Canje_de_Ptos.CanjePuntos frm = new Canje_de_Ptos.CanjePuntos();
            frm.ShowDialog(this);
        }


    }
}
